from rest_framework import serializers

from apps.plan.models import Plan
from apps.plan.models import PlanCase
from apps.case.models import Case
from apps.steps.models import Steps
from collections.abc import Iterable


class PlanListSerializers(serializers.ModelSerializer):
    project_name = serializers.CharField(source='project.name')

    class Meta:
        model = Plan
        fields = ['id', 'name', 'project', 'project_name', 'remark', 'add_time', 'edit_time']


class PlanSerializers(serializers.ModelSerializer):
    class Meta:
        model = Plan
        fields = '__all__'


class PlanCaseListSerializer(serializers.ModelSerializer):
    case_num = serializers.CharField(source='case.case_num')
    case_name = serializers.CharField(source='case.name')
    case_type = serializers.CharField(source='case.type')

    class Meta:
        model = PlanCase
        fields = ['id', 'case_num', 'case', 'case_name', 'case_type', 'add_time', 'edit_time']


class PlanCaseSerializer(serializers.ModelSerializer):
    case_detail = serializers.CharField()
    plan_name = serializers.CharField(source='plan.name', read_only=True, required=False)

    class Meta:
        model = PlanCase
        fields = '__all__'


class PlanCaseAddSerializer(serializers.ModelSerializer):
    case_ids = serializers.ListField()
    plan_id = serializers.IntegerField()

    class Meta:
        model = PlanCase
        fields = ['plan_id', 'case_ids']
